﻿//-----------------------------------------------------------------------
// <copyright file="Contacts.cs" company="Craig Longford (deltawolf7@gmail.com)">
//     Copyright (c) Craig Longford. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Delta.Mercury.Business.User
{
    using System;
    using System.Collections.Generic;
    using Delta.Data.DataExpress;

    /// <summary>
    /// Collection of contacts
    /// </summary>
    [Serializable]
    public class Contacts : List<Contact>
    {
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the Contacts class.
        /// </summary>
        public Contacts()
        {
        }
        #endregion

        #region Load Method
        /// <summary>
        /// Load all contacts of a User
        /// </summary>
        /// <param name="user">User own of the contacts</param>
        /// <param name="showDeleted">Show deleted</param>
        /// <returns>Persons contacts</returns>
        public static Contacts Load(IUser user, bool showDeleted)
        {
            Parameters parameters = new Parameters();
            parameters.Add(new Parameter("UserGuid", user.Guid));
            parameters.Add(new Parameter("Deleted", showDeleted));
            return DataAccess.GetCollection<Contacts, Contact>("LoadContacts", System.Data.CommandType.StoredProcedure, parameters);
        }
        #endregion

        #region Get Contact Type
        /// <summary>
        /// Get contacts by type
        /// </summary>
        /// <param name="typeName">Contact type name</param>
        /// <returns>Collection of contacts</returns>
        public Contacts GetContacts(string typeName)
        {
            Contacts contacts = new Contacts();
            foreach (Contact contact in this)
            {
                if (contact.Name == typeName)
                {
                    contacts.Add(contact);
                }
            }

            return contacts;
        }
        #endregion
    }
}
